﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Properties;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.ViewModel;
using Microsoft.Practices.Unity;

namespace EntLibContrib.Query.Configuration.Design.ViewModel
{
#pragma warning disable 1591
    /// <summary>
    /// This class supports block-specific configuration design-time and is not
    /// intended to be used directly from your code.
    /// </summary>
    public class QuerySettingsViewModel : SectionViewModel
    {
        public QuerySettingsViewModel(IUnityContainer builder, string sectionName, ConfigurationSection section)
            : base(builder, sectionName, section)
        {
        }

        protected override object CreateBindable()
        {
            var commands = DescendentElements()
                .Where(x => x.ConfigurationType == typeof(NameTypeConfigurationElementCollection<CommandData, CustomCommandData>))
                .First();

            var queries = DescendentElements()
                .Where(x => x.ConfigurationType == typeof(NameTypeConfigurationElementCollection<QueryDataBase, CustomQueryData>))
                .First();

            var parameterSets = DescendentElements()
                .Where(x => x.ConfigurationType == typeof(NamedElementCollection<ParameterSetData>))
                .First();

            var parameters = DescendentElements()
              .Where(x => x.ConfigurationType == typeof(NameTypeConfigurationElementCollection<ParameterData, CustomParameterData>))
              .First();

            return new HorizontalListLayout(
                new TwoVerticalsLayout(
                    new HeaderedListLayout(queries),
                    new HeaderedListLayout(commands)),
                    //new TwoColumnsLayout(
                new HeaderedListLayout(parameterSets, parameterSets.AddCommands),
                new HeaderedListLayout(parameters));
                //,1));
            //{
            //    Contained = new ElementListLayout(parameterSets.ChildElements)
            //};
            //new HeaderLayout(parameterSets.Name, parameterSets.AddCommands),
            //new HeaderLayout("Parameters") { Contained });
        }
    }
}
